import { getMapsInfo, reqMineImg, displayMap, repairIframe } from '@/service/maps';
import { message } from 'antd';

const Model = {
    namespace: 'maps',
    state: {
        mapsId: 0,
        mapsInfo: {},
        mineImg: {},
        mapIframe: ''
    },
    effects: {
        * getInfo({ payload }, { put, call }) {
            const res = yield call(getMapsInfo, payload)
            if (res.code === 200) {
                yield put({
                    type: 'saveMapsInfo',
                    payload: res.raw
                })
            } else {
                // message.error('maps请求出错')
            }
        },
        * reqMineImg({ payload }, { put, call }) {
            const res = yield call(reqMineImg, payload)
            if (res.code == 200) {
                yield put({
                    type: 'saveMineImg',
                    payload: res
                })
            }
        },
        //展示maps插件
        * displayMap({ payload }, { put, call }) {
            const res = yield call(displayMap, payload)
            console.log('displayMap', res)
            if (res.code == 200) {
                yield put({
                    type: 'saveMapIframe',
                    payload: res.path
                })
            }
        },
        //修复对比结果
        // * repairResult({ payload }, { put, call }) {
        //     const res = yield call(repairIframe, payload)
        //     console.log('repairRes', res)
        // }
    },
    reducers: {
        saveMapsInfo(state, { payload }) {
            return {...state, mapsInfo: payload }
        },
        changeMapsId(state, { payload }) {
            return {...state, mapsId: payload }
        },
        saveMineImg(state, { payload }) {
            return {...state, mineImg: payload }
        },
        saveMapIframe(state, { payload }) {
            return {...state, mapIframe: payload }
        }
    }
}
export default Model